<template>
	<view>
		<wrapBgImgVue
			bgImg="goods/goods_top.png"
		/>
		
		<navigationBarVue
			:bgImgType="1"
			navigationTitle="推广达人"
			@onTotalHeight="onTotalHeight"
		/>
		
		<view class="wrap safe-area"
			:style="'padding-top: calc(' + (topHeight) + 'px) !important;'"
			v-if="dataInfo"
		>
			<view class="head-box">
				<image
					class="bg-img"
					mode="widthFix"
					:src="common.appUrl.oss + common.imgList.tgbg"
				/>
				
				<view class="head-con">
					<view class="head-left">
						<image
							:src="$wanlshop.oss(dataInfo.user.avatar)"
							mode="aspectFill"
						/>
							
						<view class="con">
							<view class="name">
								{{ dataInfo.user.nickname }}
							</view>
							
							<view class="laber">
								{{ dataInfo.group.name }}
							</view>
						</view>
					</view>
					
					<view class="head-right">
						<!-- <view @click="commissionDetails">
							明细
						</view> -->
						
						<image
							mode="widthFix"
							:src="common.appUrl.oss + (isHidePrice ? common.imgList.show2 : common.imgList.show1)"
							@click="onHidenPrice"
						/>
					</view>
				</view>
				
				<view class="three-box">
					<view class="money-box">
						<view class="money-name">
							总收益
						</view>
						
						<view class="money-price">
							{{ isHidePrice ? '****' : dataInfo.all }}
						</view>
					</view>
					
					<view class="money-box">
						<view class="money-name">
							待入账佣金
						</view>
						
						<view class="money-price">
							{{ isHidePrice ? '****' : dataInfo.child_pay_price }}
						</view>
					</view>
					
					<view class="money-box">
						<view class="money-name">
							我的消费
						</view>
						
						<view class="money-price">
							{{ isHidePrice ? '****' : dataInfo.pay_price }}
						</view>
					</view>
				</view>
			</view>
			
			<view class="more-box">
				<view class="more-con" @click="onTeam">
					<image
						:src="common.appUrl.oss + common.imgList.tg4"
						mode="widthFix"
					/>
					
					<view>我的团队</view>
				</view>
				
				<!-- <view class="more-con" @click="commissionDetails">
					<image
						:src="common.appUrl.oss + common.imgList.tg3"
						mode="widthFix" 
					/>
					
					<view>佣金明细</view>
				</view> -->
				
				<view class="more-con" @click="distribution">
					<image
						:src="common.appUrl.oss + common.imgList.tg2"
						mode="widthFix"
					/>
					
					<view>分销订单</view>
				</view>
				
				<view class="more-con" @click="onPoster">
					<image
						:src="common.appUrl.oss+common.imgList.tg1"
						mode="widthFix"
					/>
					
					<view>邀请海报</view>
				</view>
			</view>
			
			<view>
				<block v-for="(item, index) in list" :key="index">
					<view class="list-box" >
						<view class="l-con">
							<view class="title">
								{{ item.title }}
							</view>
							
							<view class="time">
								{{ item.createtime_test }}
							</view>
						</view>
						
						<view class="words">
							{{ item.text }}
						</view>
					</view>
				</block>
			</view>
		</view>
		
		<posterPopupVue
			:isShow.sync="isShowPoster"
		/>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex';
	
	import { teamIndex, GetCommissionList } from "../API/team.js";
	
	import navigationBarVue from "../components/navigationBar/navigationBar.vue";
	import wrapBgImgVue from "../components/navigationBar/bgImg.vue";
	import posterPopupVue from '../components/popupContent/posterPopup.vue';

	export default {
		components: {
			wrapBgImgVue,
			navigationBarVue,
			posterPopupVue,
		},
		computed: {
			...mapState(['common'])
		},
		data() {
			return {
				topHeight: 0, //顶部高度
				
				dataInfo: null, //信息
				
				isHidePrice: false, //是否隐藏价格
				isShowPoster: false, //显示海报
				
				page: 1,
				total: 0,
				list: [],
			}
		},
		onShow() {
			this.getData();
			this.onRefresh();
		},
		onPullDownRefresh() {
			this.onRefresh();
		},
		onReachBottom() {
			if (this.list.length < this.total) {
				this.page++;
				this.getListData();
			}
		},
		methods: {
			/**
			 * 顶部高度
			 */
			onTotalHeight(height) {
				this.topHeight = height;
			},
			/**
			 * 隐藏价格
			 */
			onHidenPrice() {
				this.isHidePrice = !this.isHidePrice;
			},
			/**
			 * 分佣明细
			 */
			commissionDetails() {
				this.$wanlshop.to(`/pages/new/commissionDetails/commissionDetails`);
			},
			/**
			 * 团队列表
			 */
			onTeam() {
				this.$wanlshop.to(`/pages/new/team/team`);
			},
			/**
			 * 分销订单
			 */
			distribution() {
				this.$wanlshop.to(`/pages/new/distribution/distribution`);
			},
			/**
			 * 海报
			 */
			onPoster() {
				this.isShowPoster = true;
			},
			
			
			/**
			 * 刷新
			 */
			onRefresh() {
				this.page = 1;
				this.list = [];
				this.getListData();
			},
			/**
			 * 分佣记录
			 */
			getListData() {
				GetCommissionList({
					page: this.page,
					state: "2",
					time: ""
				}).then(res => {
					const list = res.data.list.data;
					this.total = res.data.list.total;
					if (this.page == 1) {
						this.list = list;
					} else {
						this.list = this.list.concat(list);
					}
				})
			},
			/**
			 * 网络请求
			 */
			getData() {
				teamIndex().then(res => {
					this.dataInfo = res.data;
				})
			},
		}
	}
</script>

<style lang="scss">
	.head-box {
		width: 690rpx;
		position: relative;
		background-color: #84BD00;
		margin-left: 30rpx;
		margin-top: 30rpx;
		border-radius: 20rpx;

		.bg-img {
			width: 100%;
			height: 100%;
			position: absolute;
			left: 0;
			right: 0;
		}

		.head-con {
			width: 610rpx;
			height: 196rpx;
			margin-left: 40rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1px solid rgba(255, 255, 255, 0.2);
			position: relative;

			.head-left {
				display: flex;
				align-items: center;

				image {
					width: 90rpx;
					height: 90rpx;
					border-radius: 50%;
				}

				.con {
					margin-left: 20rpx;

					.name {
						font-size: 30rpx;
						color: #fff;
					}

					.laber {
						width: fit-content;
						color: #84BD00;
						font-size: 22rpx;
						background-color: #fff;
						padding: 4rpx 14rpx;
						border-radius: 6rpx;
						margin-top: 10rpx;
					}
				}
			}

			.head-right {
				width: 112rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: center;

				view {
					width: 112rpx;
					height: 52rpx;
					border-radius: 50rpx;
					box-sizing: border-box;
					border: 1px solid #FFFFFF;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #FFFFFF;
				}

				image {
					width: 54rpx;
					height: 52rpx;
					margin-top: 6rpx;
				}
			}
		}

		.three-box {
			width: 610rpx;
			height: 148rpx;
			margin-left: 40rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.money-box {
				text-align: center;
				color: #FFFFFF;

				.money-name {
					font-size: 26rpx;
				}

				.money-price {
					font-size: 36rpx;
					margin-top: 8rpx;
				}
			}
		}
	}

	.more-box {
		width: 690rpx;
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 30rpx;
		margin-left: 30rpx;
		display: flex;
		padding: 40rpx 0;

		.more-con {
			flex: 1;
			display: flex;
			flex-wrap: wrap;
			justify-content: center;

			image {
				width: 60rpx;
				height: 60rpx;
			}

			view {
				width: 100%;
				text-align: center;
				font-size: 26rpx;
				color: #3D3D3D;
				margin-top: 10rpx;
			}
		}
	}

	.list-box {
		width: 690rpx;
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 30rpx;
		margin-left: 30rpx;
		padding: 36rpx 0;

		.l-con {
			width: 630rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-left: 30rpx;

			.title {
				font-size: 30rpx;
				color: #3D3D3D;
			}

			.time {
				font-size: 26rpx;
				color: #999999;
			}
		}

		.words {
			margin-left: 30rpx;
			font-size: 26rpx;
			color: #999999;
			margin-top: 14rpx;
		}
	}

	.alert-black {
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.7);
		position: fixed;
		top: 0;
		left: 0;
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-content: center;

		.alert-white {
			width: 600rpx;
			height: 600rpx;
			background-color: #fff;
			border-radius: 20rpx;
		}

		.close-box {
			width: 600rpx;
			display: flex;
			justify-content: space-between;
			margin-top: 96rpx;

			.ok {
				width: 290rpx;
				height: 82rpx;
				border-radius: 50rpx;
				background: #FFFFFF;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.no {
				width: 290rpx;
				height: 82rpx;
				border-radius: 50rpx;
				background: #84BD00;
				color: #fff;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>